package com.worldtolearn.offer.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.worldtolearn.offer.entity.Activity;

@Repository
public class ActivityDao extends HibernateDaoSupport implements IActivityDao, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Autowired
	public void init(SessionFactory factory) {
	    setSessionFactory(factory);
	}

	@Override
	public void createActivity(Activity activity) {
		getHibernateTemplate().save(activity);
		
	}

	@Override
	public void deleteActivity(Activity activity) {
		getHibernateTemplate().delete(activity);
		
	}

	@Override
	public List<Activity> getAllActivity() {
		return getHibernateTemplate().find("from Activity");
	}

	@Override
	public List<Activity> getActivityByLabelActivity(String labelActivity) {
		return getHibernateTemplate().findByNamedParam("select a from Activity a where a.labelActivity like :label", "label", labelActivity);
	}

}
